package com.ysxsoft.wdg.ui.activity.my.partner;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.GlideException;
import com.ysxsoft.wdg.R;
import com.ysxsoft.wdg.base.BaseActivity;
import com.ysxsoft.wdg.bean.response.JiFenDescriptionResponse;
import com.ysxsoft.wdg.net.CallbackCode;
import com.ysxsoft.wdg.net.UrlHost;
import com.ysxsoft.wdg.ui.activity.my.MySyActivity;
import com.ysxsoft.wdg.util.JsonUtils;
import com.ysxsoft.wdg.util.ToastUtils;
import com.ysxsoft.wdg.util.WebViewUtils;
import com.ysxsoft.wdg.util.statusbar.StatusBarUtil;
import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.callback.StringCallback;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import okhttp3.Call;

public class MyPartnerActivity extends BaseActivity {

    @BindView(R.id.topView)
    View topView;
    @BindView(R.id.title_finish)
    ImageView titleFinish;
    @BindView(R.id.title_content)
    TextView titleContent;
    @BindView(R.id.image)
    ImageView image;

    public static void start(Context context) {
        Intent intent = new Intent(context, MyPartnerActivity.class);
        context.startActivity(intent);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_my_partner;
    }

    @Override
    protected void initData() {
        StatusBarUtil.setStatusBarTextColor(this, true);
        initStatusBar(topView, true);
        titleContent.setText("我的合伙人");
        getImage();
    }

    @Override
    protected void setListener() {

    }


    @OnClick({R.id.title_finish, R.id.tv_sybb, R.id.tv_wdfs,
            R.id.tv_kstg, R.id.tv_fsdd, R.id.tv_cjwt})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.title_finish:
                finish();
                break;
            case R.id.tv_sybb://收益报表
                MySyActivity.start(mContext);
                break;
            case R.id.tv_wdfs://我的粉丝
                MyFsActivity.start(mContext);
                break;
            case R.id.tv_kstg://开始推广
                TgActivity.start(mContext);
                break;
            case R.id.tv_fsdd://粉丝订单
                FsOrderActivity.start(mContext);
                break;
            case R.id.tv_cjwt://常见问题
                CommonQuestionActivity.start(mContext);
                break;
        }
    }

    private void getImage() {
        OkHttpUtils.post()
                .url(UrlHost.HEHUO_IMAGE)
                .build().execute(new StringCallback() {
            @Override
            public void onError(Call call, Exception e, int id) {
                if (!call.isCanceled()) {
                }
            }

            @Override
            public void onResponse(String response, int id) {
                if (response != null) {
                    JiFenDescriptionResponse bean = JsonUtils.parseByGson(response, JiFenDescriptionResponse.class);
                    if (bean == null) {
                        return;
                    }
                    if (CallbackCode.SUCCESS.equals(bean.getCode())) {
                        String pic = bean.getData();
                        Glide.with(MyPartnerActivity.this).load(pic).into(image);
                    } else {
                        ToastUtils.showToast(bean.getMs());
                    }
                } else {
                }
            }
        });
    }
}
